package com.rstrulak.users.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.rstrulak.dao.UserDao;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    /**
     * The user data access object.
     */
    @Autowired
    private UserDao userDao = null;

    /**
     * {@inheritDoc}
     */
    @Override
    public UserDetails loadUserByUsername(String username) {
        UserDetails userDetails = userDao.getUserByLogin(username);
        if (userDetails == null) {
            throw new UsernameNotFoundException(username);
        }
        return userDetails;
    }

    /**
     * Getter for userDao.
     * 
     * @return the userDao
     */
    public UserDao getUserDao() {
        return userDao;
    }

    /**
     * Setter for userDao.
     * 
     * @param userDao the userDao to set
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

}
